<template>
    <el-container>
        <el-header v-if="seen">
            <cli-title-student></cli-title-student>
        </el-header>
        <el-main>
            <div class="center">
                <el-row>
                    <el-col style="width: 150px">
                        <el-aside v-if="seen">
                            <cli-menu></cli-menu>
                        </el-aside>
                    </el-col>
                    <el-col style="width: 650px">
                        <div>
                            <el-row v-if="seen" v-for="item in repositorylist" :key="id">
                                <el-card  class="box-card" @click.native="toRepository(item.collectbox_id,item.u_id)">
                                    <p>{{item.category}}</p>
                                    <p class="context">
                                        {{item.name}}
                                    </p>
                                </el-card>
                            </el-row>
                            <el-row v-if="!seen" v-for="item in repositorylist" :key="id">
                                <el-card class="box-card" @click.native="toRepository(item.collectbox_id,uid)">
                                    <p>{{item.category}}</p>
                                    <p class="context">
                                        {{item.name}}
                                    </p>
                                </el-card>
                            </el-row>
                            <el-row>
                                <el-pagination
                                        layout="prev, pager, next"
                                        :total="1000">
                                </el-pagination>
                            </el-row>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </el-main>
        <el-footer v-if="seen">
            <page-footer></page-footer>
        </el-footer>
    </el-container>
</template>

<script>
    import CliTitleStudent from "../../components/base/cliTitleStudent";
    import CliMenu from "../../components/base/cliMenu";
    import pageFooter from "../../components/base/pageFooter";
    import POST from "../../api/POST";
    import Cookies from "js-cookie";

    export default {
        name: "repositorylist",
        components: {pageFooter, CliMenu, CliTitleStudent},
        props:{
            message:String  //接收父组件传过来的值，这是老师id
        },
        methods: {
            toRepository(cid,uid) {
                this.$router.push({
                    name: 'repository-cid-repository',
                    params: {cid: cid, uid: uid}
                });
            },
            getRepositorylist() {
                let data = {};
                POST.repositoryallShowList(data).then(res => {
                    this.repositorylist = res.content
                })
            },
            getRepositorylistById(id){
                let data = {
                    'id': id,
                };
                POST.getRepositorylistById(data).then(res => {
                    this.repositorylist = res.content
                })
            },
        },
        mounted() {
            if(this.message===undefined){
                this.getRepositorylist();
                this.seen = true;
            }else{
                this.getRepositorylistById(this.message);
                this.uid = this.message;
                this.seen = false;
            }
        }        ,
        data() {
            return {
                repositorylist: [],
                seen: true,
                info: '',
                uid: ''
            }
        }
    }
</script>

<style scoped>
    .box-card {
        margin-top: 20px;

        width: 150px;
        height: 150px;
    }

    .center {
        width: 800px;
        margin: 50px auto;
    }
</style>
